<?php

header("Content-Type: application/json");
include('../../include/functions.inc.php');
$rs = $db->query_select("cllg_student", null);
$string = "[";
$index = 0;
foreach ($rs as $es) {
    $string .= ($index == 0) ? "" : ",";
    $nit = getFieldValue($db, "cllg_student", $es["ID"], "NIT");
    $nit = isset($nit[0]) ? $nit[0] : '';
    $dir = getFieldValue($db, "cllg_student", $es["ID"], "DIR_FACTURA");
    $dir = isset($dir[0]) ? $dir[0] : '';
    $name = getFieldValue($db, "cllg_student", $es["ID"], "NOMBRE_FACTURA");
    $name = isset($name[0]) ? $name[0] : '';
    $string.=json_encode(array(
        "NIT" => isset($nit["VALUE"]) ? $nit["VALUE"] : '',
        "ID" => $es["ID"],
        "NOMBRE_FACTURA" => isset($name["VALUE"]) ? $name["VALUE"] : '',
        "DIRECCION" => isset($dir["VALUE"]) ? $dir["VALUE"] : '',
        "NOMBRES" => $es["FIRST_NAME"] . ' ' . $es["SECOND_NAME"],
        "APELLIDOS" => $es["LAST_NAME"])
    );
    $index++;
}
echo $string . "]";
?>